home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Alpha ƒ / Tcl / SystemCode / modes.tcl < prev    next >
Text File  |  1996-01-23  |  19KB  |  805 lines

  1. # (nowrap)
  2. # New modes can be specified by appending to the following vars. (nowrap)
  3. # are no longer any procs such as 'setTextMode' etc.
  4.  
  5. # 'mode' is nothing when we start up.
  6. set mode {}
  7. set reverting {}
  8.  
  9.  
  10.  
  11. #================================================================================
  12. # The next two procs are called by Alpha to handle the mode flags popup menu.
  13. #================================================================================
  14.  
  15. proc getModeValuesAlpha {} {
  16.  
  17.     getWinInfo blah
  18.     lappend m "Mac" [expr {$blah(platform) == "mac"}]
  19.     lappend m "UNIX" [expr {$blah(platform) == "unix"}]
  20.     lappend m "IBM" [expr {$blah(platform) == "ibm"}] {(-} 0
  21.     lappend m "MPW" [expr {$blah(state) == "mpw"}]
  22.     lappend m "Think" [expr {$blah(state) == "think"}]
  23.     lappend m "None" [expr {$blah(state) == "none"}] {(-} 0
  24.     lappend m "Read Only" $blah(read-only) {(-} 0
  25.     lappend m "Tab Size" 0
  26.     return $m
  27. }
  28.  
  29.  
  30. proc setModeVarAlpha {var} {
  31.     global mode allFlags modeVars modifiedModeVars
  32.     global ${mode}modeVars
  33.     
  34.     set var [string tolower $var]
  35.     switch $var {
  36.         "unix"        -
  37.         "mac"        -
  38.         "ibm"        { setWinInfo platform $var }
  39.         "mpw"        -
  40.         "think"        -
  41.         "none"        { setWinInfo state $var }
  42.         "tab size"  {
  43.             getWinInfo arr
  44.             if {![catch {prompt "New tab size?" $arr(tabsize)} res]} {
  45.                 setWinInfo tabsize $res
  46.             }
  47.         }
  48.         "read only"    { 
  49.             getWinInfo b
  50.             setWinInfo read-only [expr -1 * ($b(read-only) - 1)]}
  51.     }
  52.     return
  53. }
  54.  
  55. proc modeMenuProc {menu var} {
  56.     if {![llength [winNames]]} {
  57.         alertnote "No window!"
  58.         return
  59.     }
  60.     switch $var {
  61.         "flags"         modifyModeFlags
  62.         "menus"         setModeMenus
  63.         "editPrefs"        editCurrentModePrefs
  64.         "loadPrefs"        sourceCurrentModePrefs
  65.         "describeMode"    describeMode
  66.     }
  67. }
  68.  
  69. #================================================================================
  70.  
  71.  
  72. # Suffixes used to initially determine mode for new window.
  73. set modeSuffixes { default { set winMode Text } }
  74.  
  75.  
  76. # The set of menus that the modes may choose to use.
  77. set allModeMenus {     thinkMenu cwarriorMenu toolserverMenu
  78.                     latexMenu thinkRefMenu toolboxRefMenu tclMenu perlMenu }
  79.  
  80. set modeVars { }
  81.  
  82.  
  83. # The dummy proc for a mode is called whenever we change to that mode,
  84. # so that the autoloading facility will load the correct file, if
  85. # necessary.
  86.  
  87. # The list of modes.
  88. set modes         {}
  89. set lastMode     0
  90.  
  91. # Can be used to add new mode-specific flags and variables (see think.tcl for example).
  92. proc newModeVar {mode var val isFlag} {
  93.     global ${mode}modeVars modeVars allFlags $var
  94.     
  95.     if {![info exists modeVars] || [lsearch $modeVars $var] < 0} {
  96.         lappend modeVars $var
  97.     }
  98.     if {![info exists ${mode}modeVars($var)]} {
  99.         set ${mode}modeVars($var) $val
  100.         if {![info exists $var]} {
  101.             set $var $val
  102.         }
  103.     }
  104.     if {$isFlag && (![info exists allFlags] || ([lsearch $allFlags $var] < 0))} {
  105.         lappend allFlags $var
  106.     }
  107. }
  108.  
  109. #===============================================================================
  110.  
  111.  
  112. #================================================================================
  113. if {!$alphaLite} {
  114.     source "$HOME:Tcl:SystemCode:modeDefs.tcl"
  115. }
  116.  
  117. set tcl_var_procs(stringColor) "stringColorProc"
  118. set tcl_var_procs(commentColor) "stringColorProc"
  119. set tcl_var_procs(keywordColor) "stringColorProc"
  120. set tcl_var_procs(sectionColor) "stringColorProc"
  121. set tcl_var_procs(bracesColor) "stringColorProc"
  122.  
  123. proc stringColorProc {flag} {
  124.     global $flag mode
  125.     
  126.     if {[set $flag] == "none"} {
  127.         set $flag "foreground"
  128.     }
  129.     if {$flag == "stringColor"} {
  130.         regModeKeywords -a -s $stringColor $mode
  131.     } elseif {$flag == "commentColor"} {
  132.         regModeKeywords -a -c $commentColor $mode
  133.     } elseif {$flag == "bracesColor"} {
  134.         regModeKeywords -a -I $bracesColor $mode
  135.     } elseif {($flag == "keywordColor") || ($flag == "sectionColor")} {
  136.         alertnote "Change in keyword color will take effect after Alpha restarts."
  137.         return
  138.     }
  139.     centerRedraw
  140. }
  141.  
  142. #================================================================================
  143.  
  144. proc saveVarValues {} {
  145.     global modes HOME
  146.     if {[askyesno "Save variables and values to \"$HOME:alphaFlags.tcl\"?"] == "yes"} {
  147.         set lines {}
  148.         foreach m $modes {
  149.             global ${m}modeVars
  150.             
  151.             if {[info exists ${m}modeVars]} {
  152.                 foreach v [array names ${m}modeVars] {
  153.                     append lines "set ${m}modeVars($v)\t\t\{[set ${m}modeVars($v)]\}\r"
  154.                 }
  155.                 append lines "\r"
  156.             }
  157.         }
  158.         
  159.         append lines "\r\r"
  160.         global allFlags allVars
  161.         set vars [lsort [concat $allFlags $allVars]]
  162.         eval global $vars
  163.         foreach f $vars {
  164.             append lines "set $f\t\t\{[set $f]\}\r"
  165.         }
  166.  
  167.         set fd [open "$HOME:alphaFlags.tcl" "w"]
  168.         puts $fd $lines
  169.         close $fd
  170.         message "New '$HOME:alphaFlags.tcl' written."
  171.     }
  172. }
  173.  
  174.  
  175. #================================================================================
  176.  
  177. proc setWinMode name {
  178.     global winModes modeSuffixes
  179.     set nm [file tail $name]
  180.     if {[set first [string last " <" $nm]] >= 0} {
  181.         set rname [string range $nm 0 [expr $first - 1]]
  182.     } else {
  183.         set rname $nm
  184.     }
  185.     case $rname in $modeSuffixes
  186.     set winModes($name) $winMode
  187. }
  188.  
  189.  
  190.  
  191. proc newMode mode {
  192.     global winModes modeProcs
  193.     
  194.     set name [lindex [winNames -f] 0]
  195.     changeMode $mode
  196.     set winModes($name) $mode
  197.     centerRedraw
  198. }
  199.  
  200.  
  201. proc deactivateHook name {
  202. }
  203.  
  204. proc suspendHook name {
  205.     global iconifyOnSwitch
  206.     global suspIconed
  207.     if {$iconifyOnSwitch} {
  208.         set wins [winNames -f]
  209.         set suspIconed ""
  210.         foreach win $wins {
  211.             if {![icon -f "$win" -q]} {
  212.                 lappend suspIconed $win
  213.                 icon -f "$win" -t
  214.             }
  215.         }
  216.         set suspIconed [lreverse $suspIconed]
  217.     }
  218. }
  219.  
  220.  
  221. set killCompilerErrors 0
  222.  
  223. proc resumeHook name {
  224.     global iconifyOnSwitch resumeRevert suspIconed killCompilerErrors
  225.  
  226.     if {$killCompilerErrors} {
  227.         set wins [winNames -f]
  228.         if {[set res [lsearch $wins "*Compiler Errors*"]] >= 0} {
  229.             bringToFront [lindex $wins $res]
  230.             killWindow
  231.         }
  232.     }
  233.     
  234.     if {$iconifyOnSwitch && [info exists suspIconed]} {
  235.         set wins [winNames -f]
  236.         foreach win $suspIconed {
  237.             icon -f "$win" -o
  238.         }
  239.         unset suspIconed
  240.     }
  241.     if {$resumeRevert} {
  242.         set resumeRevert 0
  243.         revert
  244.     }
  245. }
  246.  
  247.  
  248.  
  249. # Handles dynamically adding and deleting window names from menu.
  250. proc addWinName name {
  251.     global winNameToNum winMenu winNumToName
  252.     
  253.     for {set i 0} {$i<100} {incr i} {
  254.         if {[catch {set nm $winNumToName($i)} res] == "1"} {
  255.             regexp {[^:]*$} $name nm
  256.             if {$i < 10} {
  257.                 addMenuItem -m -l "/$i" $winMenu $nm
  258.             } else {
  259.                 addMenuItem -m -l "" $winMenu $nm
  260.             }
  261.             set winNumToName($i) $name
  262.             set winNameToNum($name) $i
  263.             return
  264.         }
  265.     }
  266. }
  267.  
  268. proc removeWinName name {
  269.     global winNameToNum winNumToName winMenu
  270.     
  271.     set num $winNameToNum($name)
  272.     unset winNumToName($num)
  273.     unset winNameToNum($name)
  274.     regexp {[^:]*$} $name nm
  275.     deleteMenuItem -m $winMenu $nm
  276. }
  277.  
  278.  
  279. proc menuWin {menu name} {
  280.     global winNameToNum
  281.  
  282.     set nms [array names winNameToNum]
  283.  
  284.     if {[lsearch $nms "*$name"] < 0} {
  285.         $name
  286.         return
  287.     }
  288.  
  289.     foreach nm $nms {
  290.         if {[string match *$name $nm] == "1"}  {
  291.             bringToFront $name
  292.             if [icon -q] { icon -f $name -o }
  293.             return
  294.         }
  295.     }
  296.     return "normal"
  297. }
  298.  
  299.  
  300. # Do not move 'displayMode' calls!
  301. proc changeMode {newMode} {
  302.     global lastMode modeMenus dummyProc mode seenMode PREFS
  303.     
  304.     set lastMode $mode
  305.     set mode $newMode
  306.     if {$lastMode == $mode} {
  307.         catch {displayMode $newMode}
  308.         return
  309.     }
  310.  
  311.     # Used to be after the modeVar stuff. Why?
  312.     if {[info exists dummyProc($mode)]} { $dummyProc($mode) }
  313.  
  314.     global ${mode}modeVars
  315.     if {[info exists ${mode}modeVars]} {
  316.         foreach v [array names ${mode}modeVars] {
  317.             global $v
  318.             set $v [set ${mode}modeVars($v)]
  319.         }
  320.     }
  321.  
  322.     if {[info exists modeMenus($lastMode)]} {
  323.         foreach m $modeMenus($lastMode) {
  324.             global $m
  325.             catch {removeMenu [set $m]}
  326.         }
  327.     }
  328.     if {[info exists modeMenus($mode)]} {
  329.         foreach m $modeMenus($mode) {
  330.             catch {$m}
  331.             global $m
  332.             catch {insertMenu [set $m]}
  333.         }
  334.     }
  335.     
  336.     if {![info exists seenMode($mode)]} {
  337.         if {[file exists "$PREFS:${mode}Prefs.tcl"]} {
  338.             source "$PREFS:${mode}Prefs.tcl"
  339.         }
  340.         set seenMode($mode) 1
  341.     }
  342.         
  343.     catch {displayMode $newMode}
  344. }
  345.  
  346.  
  347. proc setModeMenus {} {
  348.     global mode modeMenus allModeMenus modifiedModeMenus
  349.  
  350.     set menus [listpick -p "Pick menus for mode '$mode':" -l -L $modeMenus($mode) [lsort $allModeMenus]]
  351.     set modeMenus($mode) $menus
  352.  
  353.     lappend modifiedModeMenus $mode
  354.  
  355.     foreach m $allModeMenus {
  356.         global $m
  357.         catch {removeMenu [set $m]}
  358.     }
  359.     foreach m $menus {
  360.         global $m
  361.         catch {$m}
  362.         catch {insertMenu [set $m]}
  363.     }
  364. }
  365.  
  366.  
  367. #=============================================================================
  368. # Hook procs recognized: "openHook", "closeHook", "activateHook", "deactivateHook", 
  369. #                          "suspendHook", "saveasHook", "saveHook", and "resumeHook".
  370. #=============================================================================
  371.  
  372. if {![info exists winActive]} {set winActive ""}
  373.  
  374. # Event hooks - set specific modes when files opened.
  375.  
  376.  
  377. proc openHook name {
  378.     global winModes autoMark mode screenHeight screenWidth forceMainScreen recentFiles recentFilesCount 
  379.  
  380.     changeMode $winModes($name)
  381.     if {$name == {*Toolserver shell*}} startMPW
  382.     addWinName $name
  383.     message ""
  384.  
  385.     if {![catch {getFileInfo $name info}]} {
  386.         if {$info(creator) == {ttxt}} {
  387.             setWinInfo dirty 0
  388.         }
  389.         if {$info(type) == {ttro}} {
  390.             catch {setWinInfo read-only 1}
  391.             message "Read-only!"
  392.         }
  393.     }
  394.  
  395.     global ${mode}modeVars
  396.     
  397.     if {$forceMainScreen} {
  398.         set geo [getGeometry]
  399.         set l [lindex $geo 0]; set t [lindex $geo 1]; set w [lindex $geo 2]; set h [lindex $geo 3]; 
  400.         if {($l < 0) || ($t < 35) || ([expr $l + $w] > $screenWidth) || ([expr $t + $h + 18] > $screenHeight)} {
  401.             singlePage
  402.         }
  403.     }
  404.     getWinInfo arr
  405.     if {[info exists ${mode}modeVars(autoMark)] && [set ${mode}modeVars(autoMark)] && !$arr(read-only) && ![llength [getNamedMarks -n]]} {
  406.         markFile
  407.     }
  408.     
  409.     if {[string match "*Preferences*defs.tcl" $name]} {setWinInfo read-only 1}
  410.     
  411.     pushRecent $name 
  412. }
  413.  
  414.  
  415. # full pathname
  416. proc saveHook name {
  417.     global backup backExtension backDir mode
  418.     
  419.     if {($mode == "C") || ($mode == "C++")} {catch {modified}}
  420.  
  421.     if ($backup) {
  422.         if {![string length [set dir $backDir]]} {
  423.             set dir [file dirname $name]
  424.         }
  425.         if {![file exists $dir]} {
  426.             if {[askyesno "Create backup dir '$dir'?"] == "yes"} {
  427.                 mkdir $dir
  428.             }
  429.         }
  430.         catch {rm $dir:[file tail $name]$backExtension}
  431.         catch {cp $name $dir:[file tail $name]$backExtension}
  432.     }
  433. }
  434.  
  435. proc revertToBackup {} {
  436.     global backup backExtension backDir winModes 
  437.  
  438.     set fname [lindex [winNames -f] 0]
  439.     set bname "$backDir:[file tail $fname]$backExtension"
  440.     if {![file exists $bname]} {
  441.         message "Backup file '$bname' does not exist"
  442.         return
  443.     }
  444.     
  445.     if {[askyesno "Revert to backup dated '[join [mtime [file mtime $bname]]]'?"] == "yes"} {
  446.         killWindow
  447.         
  448.         edit $bname
  449.         saveAs -f $fname
  450.     }
  451. }
  452.  
  453.  
  454.  
  455. # Clean up the mark stack.
  456. proc closeHook name {
  457.     global markStack winModes winActive
  458.  
  459.     unset winModes($name)
  460.     if [llength $markStack] {
  461.         set markStack [removePat $markStack $name*]
  462.     }
  463.     removeWinName $name
  464.  
  465.     if {[set ind [lsearch $winActive $name]] >= 0} {
  466.         set winActive [lreplace $winActive $ind $ind]
  467.     }
  468.  
  469.     catch {unset winModes($name)}
  470. }
  471.  
  472.  
  473. proc saveasHook {oldName newName} {
  474.     global winModes winActive
  475.     removeWinName $oldName
  476.     addWinName $newName
  477.     setWinMode $newName
  478.     changeMode $winModes($newName)
  479.     
  480.     pushRecent $newName
  481.     
  482.     if {[set ind [lsearch $winActive $oldName]] >= 0} {
  483.         set winActive [lreplace $winActive $ind $ind]
  484.     }
  485.     set winActive [linsert $winActive 0 $newName]
  486.     catch {unset winModes($oldName)}
  487. }
  488.  
  489. if {![info exists actives]} {set actives 0}
  490.  
  491. # and, install a new 'winActive' patch , to 'activateHook':
  492.  
  493. proc activateHook name {
  494.     global winModes winActive
  495.  
  496.     if {![info exists winModes($name)]} {
  497.         setWinMode $name
  498.     }
  499.     changeMode $winModes($name)
  500.  
  501.     if {[set ind [lsearch $winActive $name]] == -1} {
  502.         set winActive [linsert $winActive 0 $name]
  503.         return
  504.     }
  505.     if {$ind >= 1} {
  506.         set winActive [lreplace $winActive $ind $ind]
  507.         set winActive [linsert $winActive 0 $name]
  508.     }
  509.  
  510. }
  511.  
  512.  
  513. proc dirtyHook {name dirty} {
  514.     global winMenu
  515.     markMenuItem $winMenu [file tail $name] $dirty "╫"
  516. }
  517.  
  518.  
  519. set modifiedVars        {}
  520. set modifiedArrVars        {}
  521. set modifiedModeVars    {}
  522. set modifiedModeMenus    {}
  523.  
  524.  
  525. proc quitHook {} {
  526.     global quitHooks
  527.     saveModifiedVars
  528.     if {[info exists quitHooks]} {
  529.         foreach item $quitHooks {
  530.             $item
  531.         }
  532.     }
  533. }
  534.  
  535.  
  536. proc saveModifiedVars {} {
  537.     global modifiedVars modifiedModeVars modifiedArrVars modifiedModeMenus modeMenus prefDefs recentFilesSave recentFiles
  538.  
  539.     if {[llength $modifiedVars] || [llength $modifiedArrVars] || [llength $modifiedModeVars] || [llength $modifiedModeMenus]} {
  540.         foreach f [removeDups $modifiedModeMenus] {
  541.             addArrDef modeMenus $f $modeMenus($f)
  542.         }
  543.         foreach f [removeDups $modifiedArrVars] {
  544.             global $f
  545.             foreach ind [array names $f] {
  546.                 addArrDef $f $ind [set ${f}($ind)]
  547.             }
  548.         }
  549.         foreach f [removeDups $modifiedVars] {
  550.             global $f
  551.             addDef $f [set $f]
  552.         }
  553.         foreach f [removeDups $modifiedModeVars] {
  554.             set nm [lindex $f 0]
  555.             set mode [lindex $f 1]
  556.             global $mode
  557.             addArrDef [set mode] $nm [set [set mode]($nm)]
  558.         }
  559.     }
  560.     
  561.     if {[info exists recentFiles]} {
  562.         addDef recentFilesSave $recentFiles
  563.     }
  564.  
  565.     set modifiedVars {}
  566.     set modifiedArrVars {}
  567.     set modifiedModeVars {}
  568.     set modifiedModeMenus {}
  569. }
  570.  
  571. #================================================================================
  572.  
  573. proc describeMode {} {
  574.     global mode modeSuffixes modeMenus modes
  575.     global ${mode}modeVars
  576.     
  577.     set text "\r\tMODE $mode\r\r"
  578.     set suffs ""
  579.     set first 1
  580.     foreach suf $modeSuffixes {
  581.         if {([llength $suf] == 3) && ([lindex $suf 1] == "winMode") && ([lindex $suf 2] == $mode)} {
  582.             if {$first} {
  583.                 lappend suffs $last
  584.                 set first 0
  585.             } else {
  586.                 append suffs ", $last"
  587.             }
  588.         }
  589.         set last $suf
  590.     }
  591.     append text "Mode suffixes: $suffs\r\r"
  592.     
  593.     set first 1
  594.     append text "Mode menus: "
  595.     if {[info exists modeMenus($mode)]} {
  596.         foreach m $modeMenus($mode) {
  597.             if $first {
  598.                 set first 0
  599.                 lappend text $m
  600.             } else {
  601.                 append text ", $m"
  602.             }
  603.         }
  604.     }
  605.     append text "\r\r"
  606.  
  607.     append text "Mode-specific variables:\r"
  608.     if {[info exists ${mode}modeVars]} {
  609.         foreach v [lsort [array names ${mode}modeVars]] {
  610.             append text [format "\t%-20s: \"%s\"\r" $v [set ${mode}modeVars($v)]]
  611.         }
  612.     }
  613.  
  614.  
  615.     set etext "\rMode-independent bindings:\r"
  616.     append text "\rMode-specific bindings:\r"
  617.     foreach b [split [bindingList] "\r"] {
  618.         set lst [lindex $b end]
  619.         if {$lst == $mode} {
  620.             append text "\t$b\r"
  621.         } elseif {[lsearch $modes $lst] < 0} {
  622.             append etext "\t$b\r"
  623.         }
  624.     }
  625.     new -n "* <$mode> MODE *"
  626.     insertText $text$etext
  627.     goto 0
  628.     
  629.     setWinInfo dirty 0
  630. }
  631.  
  632.  
  633. #================================================================================
  634. lappend modes Text
  635. set modeMenus(Text)                { }
  636. newModeVar Text leftFillColumn {0} 0
  637. newModeVar Text suffixString { <--} 0
  638. newModeVar Text prefixString {> } 0
  639. newModeVar Text fillColumn {75} 0
  640. newModeVar Text wordWrap {1} 1
  641. newModeVar Text wordBreak {[a-zA-Z0-9_]+} 0
  642. newModeVar Text wordBreakPreface {([^a-zA-Z0-9_])} 0
  643. newModeVar Text wrapBreak {[a-zA-Z0-9_]+} 0
  644. newModeVar Text wrapBreakPreface {([^a-zA-Z0-9_])} 0
  645. newModeVar Text autoMark    0    1
  646.  
  647. #===============================================================================
  648.  
  649.  
  650. set flagPrefs(Backups) {backup}
  651. set varPrefs(Backups) {backDir backExtension}
  652. set flagPrefs(Gui) { blinkingCursor blockCursor coloring dragAndDrop iconifyOnSwitch intelCutPaste lockStatus showEudoraMenu showInvisibles } 
  653. set varPrefs(Gui)  {defaultFont fontSize tabSize}
  654. set flagPrefs(Printer) {printHeader printHeaderFullPath printHeaderTime}
  655. set varPrefs(Printer) {bottomMargin printerFont printerFontSize topMargin leftMargin}
  656. set flagPrefs(Tags) {}
  657. set varPrefs(Tags) {funcPar tagFile}
  658. set flagPrefs(Window) {autoHScroll forceMainScreen horScrollBar moveInsertion powerThumb sortedIsDefault}
  659. set varPrefs(Window) {defHeight defLeft defTop defWidth horMargin }
  660. set flagPrefs(Tiling) {}
  661. set varPrefs(Tiling) {numWinsToTile tileHeight tileLeft tileMargin tileTop tileWidth }
  662. set flagPrefs(Wrapping) {}
  663. set varPrefs(Wrapping) {paraColumn wrapLow wrapHigh}
  664.  
  665. set flagPrefs(Miscellaneous) {}
  666. foreach f $allFlags {
  667.     if {([lsearch $modeVars $f] < 0) && ([lsearch $flagPrefs(Tiling) $f] < 0) && ([lsearch $flagPrefs(Backups) $f] < 0) && ([lsearch $flagPrefs(Gui) $f] < 0) && ([lsearch $flagPrefs(Printer) $f] < 0) && ([lsearch $flagPrefs(Tags) $f] < 0) && ([lsearch $flagPrefs(Window) $f] < 0) && ([lsearch $flagPrefs(Wrapping) $f] < 0)} {
  668.         lappend flagPrefs(Miscellaneous) $f
  669.     }
  670. }
  671.  
  672. set varPrefs(Miscellaneous) {}
  673. foreach f $allVars {
  674.     if {([lsearch $modeVars $f] < 0) && ([lsearch $varPrefs(Tiling) $f] < 0) && ([lsearch $varPrefs(Backups) $f] < 0) && ([lsearch $varPrefs(Gui) $f] < 0) && ([lsearch $varPrefs(Printer) $f] < 0) && ([lsearch $varPrefs(Tags) $f] < 0) && ([lsearch $varPrefs(Window) $f] < 0) && ([lsearch $varPrefs(Wrapping) $f] < 0)} {
  675.         lappend varPrefs(Miscellaneous) $f
  676.     }
  677. }
  678.  
  679.  
  680. proc globalOptions {menu item {is_mode ""}} {
  681.     global flagPrefs varPrefs maxT tcl_var_procs modifiedVars
  682.  
  683.     if {[string length $is_mode]} {
  684.         set args {}
  685.         set nvars [llength $item]
  686.         lappend args [list "Page 1" $menu [lrange $item 0 [expr ($nvars / 2) - 1]]]
  687.         lappend args [list "Page 2" {} [lrange $item [expr ($nvars / 2)] end]]
  688.     } else {
  689.         if {$item != "flags"} {
  690.             return [$item]
  691.         }
  692.         
  693.         set args {}
  694.         foreach nm [array names flagPrefs] {
  695.             lappend args [list $nm $flagPrefs($nm) $varPrefs($nm)]
  696.         }
  697.     }
  698.     
  699.     set left 20
  700.     
  701.     set height [expr 500 + 60]
  702.  
  703.     set names {}
  704.     set maxT 0
  705.     foreach arg [lsort $args] {
  706.         if {[llength $arg] != 3} {error "Bad structure"}
  707.         lappend names [lindex $arg 0]
  708.         set flags [lindex $arg 1]
  709.         set vars [lindex $arg 2]
  710.         append editItems " " $flags " " $vars
  711.         append cmd " -n \{[lindex $arg 0]\} " [dialSet $flags $vars]
  712.     }
  713.  
  714.     set height [expr $maxT + 30]
  715.     set buttons [concat -b OK $left [expr $height-30] [expr $left + 60] [expr $height-10] -b Cancel [expr $left + 100] [expr $height-30] [expr $left + 160] [expr $height-10]]
  716.     global blah
  717.     set res [eval [concat dialog -w 480 -h $height -t "Preferences:" 60 10 140 30 $buttons [list -m [concat [list [lindex $names 0]] $names] 150 10 255 30]  $cmd]]
  718.  
  719.     set changed {}
  720.     
  721.     if {[lindex $res 0]} {
  722.         set res [lrange $res 3 end]
  723.         
  724.         if {[string length $is_mode]} {
  725.             return $res
  726.         }
  727.         
  728.         foreach item $editItems {
  729.             set val [lindex $res 0]
  730.             set res [lrange $res 1 end]
  731.             
  732.             global $item
  733.             if {[set $item] != $val} {
  734.                 set $item $val
  735.                 if {[info exists tcl_var_procs($item)]} {
  736.                     $tcl_var_procs($item) $item
  737.                 }
  738.                 lappend modifiedVars $item
  739.             }
  740.         }
  741.     } else {
  742.         error "Cancel chosen"
  743.     }
  744. }
  745.  
  746.  
  747. proc modifyModeFlags {} {
  748.     global mode invisibleMode modifiedModeVars
  749.     global ${mode}modeVars
  750.     global allFlags tcl_var_procs
  751.  
  752.     if {![llength [winNames]]} {
  753.         alertnote "No window!"
  754.         return
  755.     }
  756.  
  757.     set flags {}
  758.     set vars {}
  759.     
  760.     if {[info exists ${mode}modeVars]} {
  761.  
  762.         foreach v [lsort [array names ${mode}modeVars]] {
  763.             if {[info exists invisibleModeVars($v)]} continue
  764.             
  765.             if {[lsearch $allFlags $v] >= 0} {
  766.                 lappend flags $v
  767.             } else {
  768.                 lappend vars $v
  769.             }
  770.         }
  771.         set flags [lsort $flags]
  772.         set vars [lsort $vars]
  773.         
  774.         if {$mode == "TeX"} {
  775.             set res [globalOptions $flags $vars "yes"]
  776.         } else {
  777.             set res [modeDialog $flags $vars]
  778.         }
  779.         
  780.         foreach flag [concat $flags $vars] {
  781.             global $flag
  782.             set val [lindex $res 0]
  783.             set res [lrange $res 1 end]
  784.             
  785.             if {[set $flag] != $val} {
  786.                 set $flag $val
  787.                 set ${mode}modeVars($flag) $val
  788.                 lappend modifiedModeVars [list $flag ${mode}modeVars]
  789.  
  790.                 if {[info exists tcl_var_procs($flag)]} {
  791.                     $tcl_var_procs($flag) $flag
  792.                 }
  793.             }
  794.         }
  795.     }
  796. }
  797.  
  798.  
  799. proc modifyModeString {flag} {
  800.     global stringColor mode
  801.     
  802.     regModeKeywords -a -s $stringColor $mode
  803.     centerRedraw
  804. }
  805.